package qldc.pm.tiensu.service.persistence;

import com.liferay.portal.kernel.cache.CacheRegistryUtil;
import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderPath;
import com.liferay.portal.kernel.dao.orm.Query;
import com.liferay.portal.kernel.dao.orm.QueryPos;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.InstanceFactory;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.PropsKeys;
import com.liferay.portal.kernel.util.PropsUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.kernel.util.UnmodifiableList;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.ModelListener;
import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;

import qldc.pm.tiensu.NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException;
import qldc.pm.tiensu.model.TEMP_PhieuThongTinVeNguoiCoTienSu;
import qldc.pm.tiensu.model.impl.TEMP_PhieuThongTinVeNguoiCoTienSuImpl;
import qldc.pm.tiensu.model.impl.TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl;
import qldc.pm.tiensu.service.persistence.TEMP_PhieuThongTinVeNguoiCoTienSuPersistence;

import java.io.Serializable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * The persistence implementation for the t e m p_ phieu thong tin ve nguoi co tien su service.
 *
 * <p>
 * Caching information and settings can be found in <code>portal.properties</code>
 * </p>
 *
 * @author Brian Wing Shun Chan
 * @see TEMP_PhieuThongTinVeNguoiCoTienSuPersistence
 * @see TEMP_PhieuThongTinVeNguoiCoTienSuUtil
 * @generated
 */
public class TEMP_PhieuThongTinVeNguoiCoTienSuPersistenceImpl
    extends BasePersistenceImpl<TEMP_PhieuThongTinVeNguoiCoTienSu>
    implements TEMP_PhieuThongTinVeNguoiCoTienSuPersistence {
    /*
     * NOTE FOR DEVELOPERS:
     *
     * Never modify or reference this class directly. Always use {@link TEMP_PhieuThongTinVeNguoiCoTienSuUtil} to access the t e m p_ phieu thong tin ve nguoi co tien su persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
     */
    public static final String FINDER_CLASS_NAME_ENTITY = TEMP_PhieuThongTinVeNguoiCoTienSuImpl.class.getName();
    public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
        ".List1";
    public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
        ".List2";
    public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.ENTITY_CACHE_ENABLED,
            TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.FINDER_CACHE_ENABLED,
            TEMP_PhieuThongTinVeNguoiCoTienSuImpl.class,
            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
    public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.ENTITY_CACHE_ENABLED,
            TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.FINDER_CACHE_ENABLED,
            TEMP_PhieuThongTinVeNguoiCoTienSuImpl.class,
            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
    public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.ENTITY_CACHE_ENABLED,
            TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.FINDER_CACHE_ENABLED,
            Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll",
            new String[0]);
    public static final FinderPath FINDER_PATH_FETCH_BY_MASOHOSOTIENSUTUTOAAN = new FinderPath(TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.ENTITY_CACHE_ENABLED,
            TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.FINDER_CACHE_ENABLED,
            TEMP_PhieuThongTinVeNguoiCoTienSuImpl.class,
            FINDER_CLASS_NAME_ENTITY, "fetchByMaSoHoSoTienSuTuToaAn",
            new String[] { String.class.getName() },
            TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.MASOHOSOTIENSUTUTOAAN_COLUMN_BITMASK);
    public static final FinderPath FINDER_PATH_COUNT_BY_MASOHOSOTIENSUTUTOAAN = new FinderPath(TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.ENTITY_CACHE_ENABLED,
            TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.FINDER_CACHE_ENABLED,
            Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
            "countByMaSoHoSoTienSuTuToaAn",
            new String[] { String.class.getName() });
    private static final String _FINDER_COLUMN_MASOHOSOTIENSUTUTOAAN_MASOHOSOTIENSUTUTOAAN_1 =
        "temp_PhieuThongTinVeNguoiCoTienSu.maSoHoSoTienSuTuToaAn IS NULL";
    private static final String _FINDER_COLUMN_MASOHOSOTIENSUTUTOAAN_MASOHOSOTIENSUTUTOAAN_2 =
        "temp_PhieuThongTinVeNguoiCoTienSu.maSoHoSoTienSuTuToaAn = ?";
    private static final String _FINDER_COLUMN_MASOHOSOTIENSUTUTOAAN_MASOHOSOTIENSUTUTOAAN_3 =
        "(temp_PhieuThongTinVeNguoiCoTienSu.maSoHoSoTienSuTuToaAn IS NULL OR temp_PhieuThongTinVeNguoiCoTienSu.maSoHoSoTienSuTuToaAn = '')";
    public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_SODINHDANHCANHAN =
        new FinderPath(TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.ENTITY_CACHE_ENABLED,
            TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.FINDER_CACHE_ENABLED,
            TEMP_PhieuThongTinVeNguoiCoTienSuImpl.class,
            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findBySoDinhDanhCaNhan",
            new String[] {
                String.class.getName(),
                
            Integer.class.getName(), Integer.class.getName(),
                OrderByComparator.class.getName()
            });
    public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SODINHDANHCANHAN =
        new FinderPath(TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.ENTITY_CACHE_ENABLED,
            TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.FINDER_CACHE_ENABLED,
            TEMP_PhieuThongTinVeNguoiCoTienSuImpl.class,
            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
            "findBySoDinhDanhCaNhan", new String[] { String.class.getName() },
            TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.SODINHDANHCANHAN_COLUMN_BITMASK |
            TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.CREATEDATE_COLUMN_BITMASK);
    public static final FinderPath FINDER_PATH_COUNT_BY_SODINHDANHCANHAN = new FinderPath(TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.ENTITY_CACHE_ENABLED,
            TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.FINDER_CACHE_ENABLED,
            Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
            "countBySoDinhDanhCaNhan", new String[] { String.class.getName() });
    private static final String _FINDER_COLUMN_SODINHDANHCANHAN_SODINHDANHCANHAN_1 =
        "temp_PhieuThongTinVeNguoiCoTienSu.soDinhDanhCaNhan IS NULL";
    private static final String _FINDER_COLUMN_SODINHDANHCANHAN_SODINHDANHCANHAN_2 =
        "temp_PhieuThongTinVeNguoiCoTienSu.soDinhDanhCaNhan = ?";
    private static final String _FINDER_COLUMN_SODINHDANHCANHAN_SODINHDANHCANHAN_3 =
        "(temp_PhieuThongTinVeNguoiCoTienSu.soDinhDanhCaNhan IS NULL OR temp_PhieuThongTinVeNguoiCoTienSu.soDinhDanhCaNhan = '')";
    public static final FinderPath FINDER_PATH_FETCH_BY_TIENSUID = new FinderPath(TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.ENTITY_CACHE_ENABLED,
            TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.FINDER_CACHE_ENABLED,
            TEMP_PhieuThongTinVeNguoiCoTienSuImpl.class,
            FINDER_CLASS_NAME_ENTITY, "fetchByTienSuId",
            new String[] { Long.class.getName() },
            TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.TIENSUID_COLUMN_BITMASK);
    public static final FinderPath FINDER_PATH_COUNT_BY_TIENSUID = new FinderPath(TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.ENTITY_CACHE_ENABLED,
            TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.FINDER_CACHE_ENABLED,
            Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
            "countByTienSuId", new String[] { Long.class.getName() });
    private static final String _FINDER_COLUMN_TIENSUID_TIENSUID_2 = "temp_PhieuThongTinVeNguoiCoTienSu.tienSuId = ?";
    public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_NOITHUONGTRUDIACHI =
        new FinderPath(TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.ENTITY_CACHE_ENABLED,
            TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.FINDER_CACHE_ENABLED,
            TEMP_PhieuThongTinVeNguoiCoTienSuImpl.class,
            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByNoiThuongTruDiaChi",
            new String[] {
                String.class.getName(),
                
            Integer.class.getName(), Integer.class.getName(),
                OrderByComparator.class.getName()
            });
    public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NOITHUONGTRUDIACHI =
        new FinderPath(TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.ENTITY_CACHE_ENABLED,
            TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.FINDER_CACHE_ENABLED,
            TEMP_PhieuThongTinVeNguoiCoTienSuImpl.class,
            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
            "findByNoiThuongTruDiaChi",
            new String[] { String.class.getName() },
            TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.NOITHUONGTRUDIACHI_COLUMN_BITMASK |
            TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.CREATEDATE_COLUMN_BITMASK);
    public static final FinderPath FINDER_PATH_COUNT_BY_NOITHUONGTRUDIACHI = new FinderPath(TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.ENTITY_CACHE_ENABLED,
            TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.FINDER_CACHE_ENABLED,
            Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
            "countByNoiThuongTruDiaChi", new String[] { String.class.getName() });
    private static final String _FINDER_COLUMN_NOITHUONGTRUDIACHI_NOITHUONGTRUDIACHI_1 =
        "temp_PhieuThongTinVeNguoiCoTienSu.noiThuongTruDiaChi IS NULL";
    private static final String _FINDER_COLUMN_NOITHUONGTRUDIACHI_NOITHUONGTRUDIACHI_2 =
        "temp_PhieuThongTinVeNguoiCoTienSu.noiThuongTruDiaChi = ?";
    private static final String _FINDER_COLUMN_NOITHUONGTRUDIACHI_NOITHUONGTRUDIACHI_3 =
        "(temp_PhieuThongTinVeNguoiCoTienSu.noiThuongTruDiaChi IS NULL OR temp_PhieuThongTinVeNguoiCoTienSu.noiThuongTruDiaChi = '')";
    private static final String _SQL_SELECT_TEMP_PHIEUTHONGTINVENGUOICOTIENSU = "SELECT temp_PhieuThongTinVeNguoiCoTienSu FROM TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu";
    private static final String _SQL_SELECT_TEMP_PHIEUTHONGTINVENGUOICOTIENSU_WHERE =
        "SELECT temp_PhieuThongTinVeNguoiCoTienSu FROM TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu WHERE ";
    private static final String _SQL_COUNT_TEMP_PHIEUTHONGTINVENGUOICOTIENSU = "SELECT COUNT(temp_PhieuThongTinVeNguoiCoTienSu) FROM TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu";
    private static final String _SQL_COUNT_TEMP_PHIEUTHONGTINVENGUOICOTIENSU_WHERE =
        "SELECT COUNT(temp_PhieuThongTinVeNguoiCoTienSu) FROM TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu WHERE ";
    private static final String _ORDER_BY_ENTITY_ALIAS = "temp_PhieuThongTinVeNguoiCoTienSu.";
    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No TEMP_PhieuThongTinVeNguoiCoTienSu exists with the primary key ";
    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No TEMP_PhieuThongTinVeNguoiCoTienSu exists with the key {";
    private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = GetterUtil.getBoolean(PropsUtil.get(
                PropsKeys.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE));
    private static Log _log = LogFactoryUtil.getLog(TEMP_PhieuThongTinVeNguoiCoTienSuPersistenceImpl.class);
    private static TEMP_PhieuThongTinVeNguoiCoTienSu _nullTEMP_PhieuThongTinVeNguoiCoTienSu =
        new TEMP_PhieuThongTinVeNguoiCoTienSuImpl() {
            @Override
            public Object clone() {
                return this;
            }

            @Override
            public CacheModel<TEMP_PhieuThongTinVeNguoiCoTienSu> toCacheModel() {
                return _nullTEMP_PhieuThongTinVeNguoiCoTienSuCacheModel;
            }
        };

    private static CacheModel<TEMP_PhieuThongTinVeNguoiCoTienSu> _nullTEMP_PhieuThongTinVeNguoiCoTienSuCacheModel =
        new CacheModel<TEMP_PhieuThongTinVeNguoiCoTienSu>() {
            @Override
            public TEMP_PhieuThongTinVeNguoiCoTienSu toEntityModel() {
                return _nullTEMP_PhieuThongTinVeNguoiCoTienSu;
            }
        };

    public TEMP_PhieuThongTinVeNguoiCoTienSuPersistenceImpl() {
        setModelClass(TEMP_PhieuThongTinVeNguoiCoTienSu.class);
    }

    /**
     * Returns the t e m p_ phieu thong tin ve nguoi co tien su where maSoHoSoTienSuTuToaAn = &#63; or throws a {@link qldc.pm.tiensu.NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException} if it could not be found.
     *
     * @param maSoHoSoTienSuTuToaAn the ma so ho so tien su tu toa an
     * @return the matching t e m p_ phieu thong tin ve nguoi co tien su
     * @throws qldc.pm.tiensu.NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException if a matching t e m p_ phieu thong tin ve nguoi co tien su could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_PhieuThongTinVeNguoiCoTienSu findByMaSoHoSoTienSuTuToaAn(
        String maSoHoSoTienSuTuToaAn)
        throws NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException, SystemException {
        TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu = fetchByMaSoHoSoTienSuTuToaAn(maSoHoSoTienSuTuToaAn);

        if (temp_PhieuThongTinVeNguoiCoTienSu == null) {
            StringBundler msg = new StringBundler(4);

            msg.append(_NO_SUCH_ENTITY_WITH_KEY);

            msg.append("maSoHoSoTienSuTuToaAn=");
            msg.append(maSoHoSoTienSuTuToaAn);

            msg.append(StringPool.CLOSE_CURLY_BRACE);

            if (_log.isWarnEnabled()) {
                _log.warn(msg.toString());
            }

            throw new NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException(msg.toString());
        }

        return temp_PhieuThongTinVeNguoiCoTienSu;
    }

    /**
     * Returns the t e m p_ phieu thong tin ve nguoi co tien su where maSoHoSoTienSuTuToaAn = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
     *
     * @param maSoHoSoTienSuTuToaAn the ma so ho so tien su tu toa an
     * @return the matching t e m p_ phieu thong tin ve nguoi co tien su, or <code>null</code> if a matching t e m p_ phieu thong tin ve nguoi co tien su could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_PhieuThongTinVeNguoiCoTienSu fetchByMaSoHoSoTienSuTuToaAn(
        String maSoHoSoTienSuTuToaAn) throws SystemException {
        return fetchByMaSoHoSoTienSuTuToaAn(maSoHoSoTienSuTuToaAn, true);
    }

    /**
     * Returns the t e m p_ phieu thong tin ve nguoi co tien su where maSoHoSoTienSuTuToaAn = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
     *
     * @param maSoHoSoTienSuTuToaAn the ma so ho so tien su tu toa an
     * @param retrieveFromCache whether to use the finder cache
     * @return the matching t e m p_ phieu thong tin ve nguoi co tien su, or <code>null</code> if a matching t e m p_ phieu thong tin ve nguoi co tien su could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_PhieuThongTinVeNguoiCoTienSu fetchByMaSoHoSoTienSuTuToaAn(
        String maSoHoSoTienSuTuToaAn, boolean retrieveFromCache)
        throws SystemException {
        Object[] finderArgs = new Object[] { maSoHoSoTienSuTuToaAn };

        Object result = null;

        if (retrieveFromCache) {
            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_MASOHOSOTIENSUTUTOAAN,
                    finderArgs, this);
        }

        if (result instanceof TEMP_PhieuThongTinVeNguoiCoTienSu) {
            TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu = (TEMP_PhieuThongTinVeNguoiCoTienSu) result;

            if (!Validator.equals(maSoHoSoTienSuTuToaAn,
                        temp_PhieuThongTinVeNguoiCoTienSu.getMaSoHoSoTienSuTuToaAn())) {
                result = null;
            }
        }

        if (result == null) {
            StringBundler query = new StringBundler(3);

            query.append(_SQL_SELECT_TEMP_PHIEUTHONGTINVENGUOICOTIENSU_WHERE);

            boolean bindMaSoHoSoTienSuTuToaAn = false;

            if (maSoHoSoTienSuTuToaAn == null) {
                query.append(_FINDER_COLUMN_MASOHOSOTIENSUTUTOAAN_MASOHOSOTIENSUTUTOAAN_1);
            } else if (maSoHoSoTienSuTuToaAn.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_MASOHOSOTIENSUTUTOAAN_MASOHOSOTIENSUTUTOAAN_3);
            } else {
                bindMaSoHoSoTienSuTuToaAn = true;

                query.append(_FINDER_COLUMN_MASOHOSOTIENSUTUTOAAN_MASOHOSOTIENSUTUTOAAN_2);
            }

            String sql = query.toString();

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                QueryPos qPos = QueryPos.getInstance(q);

                if (bindMaSoHoSoTienSuTuToaAn) {
                    qPos.add(maSoHoSoTienSuTuToaAn);
                }

                List<TEMP_PhieuThongTinVeNguoiCoTienSu> list = q.list();

                if (list.isEmpty()) {
                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MASOHOSOTIENSUTUTOAAN,
                        finderArgs, list);
                } else {
                    if ((list.size() > 1) && _log.isWarnEnabled()) {
                        _log.warn(
                            "TEMP_PhieuThongTinVeNguoiCoTienSuPersistenceImpl.fetchByMaSoHoSoTienSuTuToaAn(String, boolean) with parameters (" +
                            StringUtil.merge(finderArgs) +
                            ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
                    }

                    TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu =
                        list.get(0);

                    result = temp_PhieuThongTinVeNguoiCoTienSu;

                    cacheResult(temp_PhieuThongTinVeNguoiCoTienSu);

                    if ((temp_PhieuThongTinVeNguoiCoTienSu.getMaSoHoSoTienSuTuToaAn() == null) ||
                            !temp_PhieuThongTinVeNguoiCoTienSu.getMaSoHoSoTienSuTuToaAn()
                                                                  .equals(maSoHoSoTienSuTuToaAn)) {
                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MASOHOSOTIENSUTUTOAAN,
                            finderArgs, temp_PhieuThongTinVeNguoiCoTienSu);
                    }
                }
            } catch (Exception e) {
                FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MASOHOSOTIENSUTUTOAAN,
                    finderArgs);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        if (result instanceof List<?>) {
            return null;
        } else {
            return (TEMP_PhieuThongTinVeNguoiCoTienSu) result;
        }
    }

    /**
     * Removes the t e m p_ phieu thong tin ve nguoi co tien su where maSoHoSoTienSuTuToaAn = &#63; from the database.
     *
     * @param maSoHoSoTienSuTuToaAn the ma so ho so tien su tu toa an
     * @return the t e m p_ phieu thong tin ve nguoi co tien su that was removed
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_PhieuThongTinVeNguoiCoTienSu removeByMaSoHoSoTienSuTuToaAn(
        String maSoHoSoTienSuTuToaAn)
        throws NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException, SystemException {
        TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu = findByMaSoHoSoTienSuTuToaAn(maSoHoSoTienSuTuToaAn);

        return remove(temp_PhieuThongTinVeNguoiCoTienSu);
    }

    /**
     * Returns the number of t e m p_ phieu thong tin ve nguoi co tien sus where maSoHoSoTienSuTuToaAn = &#63;.
     *
     * @param maSoHoSoTienSuTuToaAn the ma so ho so tien su tu toa an
     * @return the number of matching t e m p_ phieu thong tin ve nguoi co tien sus
     * @throws SystemException if a system exception occurred
     */
    @Override
    public int countByMaSoHoSoTienSuTuToaAn(String maSoHoSoTienSuTuToaAn)
        throws SystemException {
        FinderPath finderPath = FINDER_PATH_COUNT_BY_MASOHOSOTIENSUTUTOAAN;

        Object[] finderArgs = new Object[] { maSoHoSoTienSuTuToaAn };

        Long count = (Long) FinderCacheUtil.getResult(finderPath, finderArgs,
                this);

        if (count == null) {
            StringBundler query = new StringBundler(2);

            query.append(_SQL_COUNT_TEMP_PHIEUTHONGTINVENGUOICOTIENSU_WHERE);

            boolean bindMaSoHoSoTienSuTuToaAn = false;

            if (maSoHoSoTienSuTuToaAn == null) {
                query.append(_FINDER_COLUMN_MASOHOSOTIENSUTUTOAAN_MASOHOSOTIENSUTUTOAAN_1);
            } else if (maSoHoSoTienSuTuToaAn.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_MASOHOSOTIENSUTUTOAAN_MASOHOSOTIENSUTUTOAAN_3);
            } else {
                bindMaSoHoSoTienSuTuToaAn = true;

                query.append(_FINDER_COLUMN_MASOHOSOTIENSUTUTOAAN_MASOHOSOTIENSUTUTOAAN_2);
            }

            String sql = query.toString();

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                QueryPos qPos = QueryPos.getInstance(q);

                if (bindMaSoHoSoTienSuTuToaAn) {
                    qPos.add(maSoHoSoTienSuTuToaAn);
                }

                count = (Long) q.uniqueResult();

                FinderCacheUtil.putResult(finderPath, finderArgs, count);
            } catch (Exception e) {
                FinderCacheUtil.removeResult(finderPath, finderArgs);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return count.intValue();
    }

    /**
     * Returns all the t e m p_ phieu thong tin ve nguoi co tien sus where soDinhDanhCaNhan = &#63;.
     *
     * @param soDinhDanhCaNhan the so dinh danh ca nhan
     * @return the matching t e m p_ phieu thong tin ve nguoi co tien sus
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<TEMP_PhieuThongTinVeNguoiCoTienSu> findBySoDinhDanhCaNhan(
        String soDinhDanhCaNhan) throws SystemException {
        return findBySoDinhDanhCaNhan(soDinhDanhCaNhan, QueryUtil.ALL_POS,
            QueryUtil.ALL_POS, null);
    }

    /**
     * Returns a range of all the t e m p_ phieu thong tin ve nguoi co tien sus where soDinhDanhCaNhan = &#63;.
     *
     * <p>
     * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link qldc.pm.tiensu.model.impl.TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
     * </p>
     *
     * @param soDinhDanhCaNhan the so dinh danh ca nhan
     * @param start the lower bound of the range of t e m p_ phieu thong tin ve nguoi co tien sus
     * @param end the upper bound of the range of t e m p_ phieu thong tin ve nguoi co tien sus (not inclusive)
     * @return the range of matching t e m p_ phieu thong tin ve nguoi co tien sus
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<TEMP_PhieuThongTinVeNguoiCoTienSu> findBySoDinhDanhCaNhan(
        String soDinhDanhCaNhan, int start, int end) throws SystemException {
        return findBySoDinhDanhCaNhan(soDinhDanhCaNhan, start, end, null);
    }

    /**
     * Returns an ordered range of all the t e m p_ phieu thong tin ve nguoi co tien sus where soDinhDanhCaNhan = &#63;.
     *
     * <p>
     * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link qldc.pm.tiensu.model.impl.TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
     * </p>
     *
     * @param soDinhDanhCaNhan the so dinh danh ca nhan
     * @param start the lower bound of the range of t e m p_ phieu thong tin ve nguoi co tien sus
     * @param end the upper bound of the range of t e m p_ phieu thong tin ve nguoi co tien sus (not inclusive)
     * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
     * @return the ordered range of matching t e m p_ phieu thong tin ve nguoi co tien sus
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<TEMP_PhieuThongTinVeNguoiCoTienSu> findBySoDinhDanhCaNhan(
        String soDinhDanhCaNhan, int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
        boolean pagination = true;
        FinderPath finderPath = null;
        Object[] finderArgs = null;

        if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
                (orderByComparator == null)) {
            pagination = false;
            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SODINHDANHCANHAN;
            finderArgs = new Object[] { soDinhDanhCaNhan };
        } else {
            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_SODINHDANHCANHAN;
            finderArgs = new Object[] {
                    soDinhDanhCaNhan,
                    
                    start, end, orderByComparator
                };
        }

        List<TEMP_PhieuThongTinVeNguoiCoTienSu> list = (List<TEMP_PhieuThongTinVeNguoiCoTienSu>) FinderCacheUtil.getResult(finderPath,
                finderArgs, this);

        if ((list != null) && !list.isEmpty()) {
            for (TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu : list) {
                if (!Validator.equals(soDinhDanhCaNhan,
                            temp_PhieuThongTinVeNguoiCoTienSu.getSoDinhDanhCaNhan())) {
                    list = null;

                    break;
                }
            }
        }

        if (list == null) {
            StringBundler query = null;

            if (orderByComparator != null) {
                query = new StringBundler(3 +
                        (orderByComparator.getOrderByFields().length * 3));
            } else {
                query = new StringBundler(3);
            }

            query.append(_SQL_SELECT_TEMP_PHIEUTHONGTINVENGUOICOTIENSU_WHERE);

            boolean bindSoDinhDanhCaNhan = false;

            if (soDinhDanhCaNhan == null) {
                query.append(_FINDER_COLUMN_SODINHDANHCANHAN_SODINHDANHCANHAN_1);
            } else if (soDinhDanhCaNhan.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_SODINHDANHCANHAN_SODINHDANHCANHAN_3);
            } else {
                bindSoDinhDanhCaNhan = true;

                query.append(_FINDER_COLUMN_SODINHDANHCANHAN_SODINHDANHCANHAN_2);
            }

            if (orderByComparator != null) {
                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
                    orderByComparator);
            } else
             if (pagination) {
                query.append(TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.ORDER_BY_JPQL);
            }

            String sql = query.toString();

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                QueryPos qPos = QueryPos.getInstance(q);

                if (bindSoDinhDanhCaNhan) {
                    qPos.add(soDinhDanhCaNhan);
                }

                if (!pagination) {
                    list = (List<TEMP_PhieuThongTinVeNguoiCoTienSu>) QueryUtil.list(q,
                            getDialect(), start, end, false);

                    Collections.sort(list);

                    list = new UnmodifiableList<TEMP_PhieuThongTinVeNguoiCoTienSu>(list);
                } else {
                    list = (List<TEMP_PhieuThongTinVeNguoiCoTienSu>) QueryUtil.list(q,
                            getDialect(), start, end);
                }

                cacheResult(list);

                FinderCacheUtil.putResult(finderPath, finderArgs, list);
            } catch (Exception e) {
                FinderCacheUtil.removeResult(finderPath, finderArgs);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return list;
    }

    /**
     * Returns the first t e m p_ phieu thong tin ve nguoi co tien su in the ordered set where soDinhDanhCaNhan = &#63;.
     *
     * @param soDinhDanhCaNhan the so dinh danh ca nhan
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the first matching t e m p_ phieu thong tin ve nguoi co tien su
     * @throws qldc.pm.tiensu.NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException if a matching t e m p_ phieu thong tin ve nguoi co tien su could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_PhieuThongTinVeNguoiCoTienSu findBySoDinhDanhCaNhan_First(
        String soDinhDanhCaNhan, OrderByComparator orderByComparator)
        throws NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException, SystemException {
        TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu = fetchBySoDinhDanhCaNhan_First(soDinhDanhCaNhan,
                orderByComparator);

        if (temp_PhieuThongTinVeNguoiCoTienSu != null) {
            return temp_PhieuThongTinVeNguoiCoTienSu;
        }

        StringBundler msg = new StringBundler(4);

        msg.append(_NO_SUCH_ENTITY_WITH_KEY);

        msg.append("soDinhDanhCaNhan=");
        msg.append(soDinhDanhCaNhan);

        msg.append(StringPool.CLOSE_CURLY_BRACE);

        throw new NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException(msg.toString());
    }

    /**
     * Returns the first t e m p_ phieu thong tin ve nguoi co tien su in the ordered set where soDinhDanhCaNhan = &#63;.
     *
     * @param soDinhDanhCaNhan the so dinh danh ca nhan
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the first matching t e m p_ phieu thong tin ve nguoi co tien su, or <code>null</code> if a matching t e m p_ phieu thong tin ve nguoi co tien su could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_PhieuThongTinVeNguoiCoTienSu fetchBySoDinhDanhCaNhan_First(
        String soDinhDanhCaNhan, OrderByComparator orderByComparator)
        throws SystemException {
        List<TEMP_PhieuThongTinVeNguoiCoTienSu> list = findBySoDinhDanhCaNhan(soDinhDanhCaNhan,
                0, 1, orderByComparator);

        if (!list.isEmpty()) {
            return list.get(0);
        }

        return null;
    }

    /**
     * Returns the last t e m p_ phieu thong tin ve nguoi co tien su in the ordered set where soDinhDanhCaNhan = &#63;.
     *
     * @param soDinhDanhCaNhan the so dinh danh ca nhan
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the last matching t e m p_ phieu thong tin ve nguoi co tien su
     * @throws qldc.pm.tiensu.NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException if a matching t e m p_ phieu thong tin ve nguoi co tien su could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_PhieuThongTinVeNguoiCoTienSu findBySoDinhDanhCaNhan_Last(
        String soDinhDanhCaNhan, OrderByComparator orderByComparator)
        throws NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException, SystemException {
        TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu = fetchBySoDinhDanhCaNhan_Last(soDinhDanhCaNhan,
                orderByComparator);

        if (temp_PhieuThongTinVeNguoiCoTienSu != null) {
            return temp_PhieuThongTinVeNguoiCoTienSu;
        }

        StringBundler msg = new StringBundler(4);

        msg.append(_NO_SUCH_ENTITY_WITH_KEY);

        msg.append("soDinhDanhCaNhan=");
        msg.append(soDinhDanhCaNhan);

        msg.append(StringPool.CLOSE_CURLY_BRACE);

        throw new NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException(msg.toString());
    }

    /**
     * Returns the last t e m p_ phieu thong tin ve nguoi co tien su in the ordered set where soDinhDanhCaNhan = &#63;.
     *
     * @param soDinhDanhCaNhan the so dinh danh ca nhan
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the last matching t e m p_ phieu thong tin ve nguoi co tien su, or <code>null</code> if a matching t e m p_ phieu thong tin ve nguoi co tien su could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_PhieuThongTinVeNguoiCoTienSu fetchBySoDinhDanhCaNhan_Last(
        String soDinhDanhCaNhan, OrderByComparator orderByComparator)
        throws SystemException {
        int count = countBySoDinhDanhCaNhan(soDinhDanhCaNhan);

        if (count == 0) {
            return null;
        }

        List<TEMP_PhieuThongTinVeNguoiCoTienSu> list = findBySoDinhDanhCaNhan(soDinhDanhCaNhan,
                count - 1, count, orderByComparator);

        if (!list.isEmpty()) {
            return list.get(0);
        }

        return null;
    }

    /**
     * Returns the t e m p_ phieu thong tin ve nguoi co tien sus before and after the current t e m p_ phieu thong tin ve nguoi co tien su in the ordered set where soDinhDanhCaNhan = &#63;.
     *
     * @param phieuThongTinVeNguoiCoTienSuId the primary key of the current t e m p_ phieu thong tin ve nguoi co tien su
     * @param soDinhDanhCaNhan the so dinh danh ca nhan
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the previous, current, and next t e m p_ phieu thong tin ve nguoi co tien su
     * @throws qldc.pm.tiensu.NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException if a t e m p_ phieu thong tin ve nguoi co tien su with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_PhieuThongTinVeNguoiCoTienSu[] findBySoDinhDanhCaNhan_PrevAndNext(
        long phieuThongTinVeNguoiCoTienSuId, String soDinhDanhCaNhan,
        OrderByComparator orderByComparator)
        throws NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException, SystemException {
        TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu = findByPrimaryKey(phieuThongTinVeNguoiCoTienSuId);

        Session session = null;

        try {
            session = openSession();

            TEMP_PhieuThongTinVeNguoiCoTienSu[] array = new TEMP_PhieuThongTinVeNguoiCoTienSuImpl[3];

            array[0] = getBySoDinhDanhCaNhan_PrevAndNext(session,
                    temp_PhieuThongTinVeNguoiCoTienSu, soDinhDanhCaNhan,
                    orderByComparator, true);

            array[1] = temp_PhieuThongTinVeNguoiCoTienSu;

            array[2] = getBySoDinhDanhCaNhan_PrevAndNext(session,
                    temp_PhieuThongTinVeNguoiCoTienSu, soDinhDanhCaNhan,
                    orderByComparator, false);

            return array;
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    protected TEMP_PhieuThongTinVeNguoiCoTienSu getBySoDinhDanhCaNhan_PrevAndNext(
        Session session,
        TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu,
        String soDinhDanhCaNhan, OrderByComparator orderByComparator,
        boolean previous) {
        StringBundler query = null;

        if (orderByComparator != null) {
            query = new StringBundler(6 +
                    (orderByComparator.getOrderByFields().length * 6));
        } else {
            query = new StringBundler(3);
        }

        query.append(_SQL_SELECT_TEMP_PHIEUTHONGTINVENGUOICOTIENSU_WHERE);

        boolean bindSoDinhDanhCaNhan = false;

        if (soDinhDanhCaNhan == null) {
            query.append(_FINDER_COLUMN_SODINHDANHCANHAN_SODINHDANHCANHAN_1);
        } else if (soDinhDanhCaNhan.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_SODINHDANHCANHAN_SODINHDANHCANHAN_3);
        } else {
            bindSoDinhDanhCaNhan = true;

            query.append(_FINDER_COLUMN_SODINHDANHCANHAN_SODINHDANHCANHAN_2);
        }

        if (orderByComparator != null) {
            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

            if (orderByConditionFields.length > 0) {
                query.append(WHERE_AND);
            }

            for (int i = 0; i < orderByConditionFields.length; i++) {
                query.append(_ORDER_BY_ENTITY_ALIAS);
                query.append(orderByConditionFields[i]);

                if ((i + 1) < orderByConditionFields.length) {
                    if (orderByComparator.isAscending() ^ previous) {
                        query.append(WHERE_GREATER_THAN_HAS_NEXT);
                    } else {
                        query.append(WHERE_LESSER_THAN_HAS_NEXT);
                    }
                } else {
                    if (orderByComparator.isAscending() ^ previous) {
                        query.append(WHERE_GREATER_THAN);
                    } else {
                        query.append(WHERE_LESSER_THAN);
                    }
                }
            }

            query.append(ORDER_BY_CLAUSE);

            String[] orderByFields = orderByComparator.getOrderByFields();

            for (int i = 0; i < orderByFields.length; i++) {
                query.append(_ORDER_BY_ENTITY_ALIAS);
                query.append(orderByFields[i]);

                if ((i + 1) < orderByFields.length) {
                    if (orderByComparator.isAscending() ^ previous) {
                        query.append(ORDER_BY_ASC_HAS_NEXT);
                    } else {
                        query.append(ORDER_BY_DESC_HAS_NEXT);
                    }
                } else {
                    if (orderByComparator.isAscending() ^ previous) {
                        query.append(ORDER_BY_ASC);
                    } else {
                        query.append(ORDER_BY_DESC);
                    }
                }
            }
        } else {
            query.append(TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Query q = session.createQuery(sql);

        q.setFirstResult(0);
        q.setMaxResults(2);

        QueryPos qPos = QueryPos.getInstance(q);

        if (bindSoDinhDanhCaNhan) {
            qPos.add(soDinhDanhCaNhan);
        }

        if (orderByComparator != null) {
            Object[] values = orderByComparator.getOrderByConditionValues(temp_PhieuThongTinVeNguoiCoTienSu);

            for (Object value : values) {
                qPos.add(value);
            }
        }

        List<TEMP_PhieuThongTinVeNguoiCoTienSu> list = q.list();

        if (list.size() == 2) {
            return list.get(1);
        } else {
            return null;
        }
    }

    /**
     * Removes all the t e m p_ phieu thong tin ve nguoi co tien sus where soDinhDanhCaNhan = &#63; from the database.
     *
     * @param soDinhDanhCaNhan the so dinh danh ca nhan
     * @throws SystemException if a system exception occurred
     */
    @Override
    public void removeBySoDinhDanhCaNhan(String soDinhDanhCaNhan)
        throws SystemException {
        for (TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu : findBySoDinhDanhCaNhan(
                soDinhDanhCaNhan, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
            remove(temp_PhieuThongTinVeNguoiCoTienSu);
        }
    }

    /**
     * Returns the number of t e m p_ phieu thong tin ve nguoi co tien sus where soDinhDanhCaNhan = &#63;.
     *
     * @param soDinhDanhCaNhan the so dinh danh ca nhan
     * @return the number of matching t e m p_ phieu thong tin ve nguoi co tien sus
     * @throws SystemException if a system exception occurred
     */
    @Override
    public int countBySoDinhDanhCaNhan(String soDinhDanhCaNhan)
        throws SystemException {
        FinderPath finderPath = FINDER_PATH_COUNT_BY_SODINHDANHCANHAN;

        Object[] finderArgs = new Object[] { soDinhDanhCaNhan };

        Long count = (Long) FinderCacheUtil.getResult(finderPath, finderArgs,
                this);

        if (count == null) {
            StringBundler query = new StringBundler(2);

            query.append(_SQL_COUNT_TEMP_PHIEUTHONGTINVENGUOICOTIENSU_WHERE);

            boolean bindSoDinhDanhCaNhan = false;

            if (soDinhDanhCaNhan == null) {
                query.append(_FINDER_COLUMN_SODINHDANHCANHAN_SODINHDANHCANHAN_1);
            } else if (soDinhDanhCaNhan.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_SODINHDANHCANHAN_SODINHDANHCANHAN_3);
            } else {
                bindSoDinhDanhCaNhan = true;

                query.append(_FINDER_COLUMN_SODINHDANHCANHAN_SODINHDANHCANHAN_2);
            }

            String sql = query.toString();

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                QueryPos qPos = QueryPos.getInstance(q);

                if (bindSoDinhDanhCaNhan) {
                    qPos.add(soDinhDanhCaNhan);
                }

                count = (Long) q.uniqueResult();

                FinderCacheUtil.putResult(finderPath, finderArgs, count);
            } catch (Exception e) {
                FinderCacheUtil.removeResult(finderPath, finderArgs);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return count.intValue();
    }

    /**
     * Returns the t e m p_ phieu thong tin ve nguoi co tien su where tienSuId = &#63; or throws a {@link qldc.pm.tiensu.NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException} if it could not be found.
     *
     * @param tienSuId the tien su ID
     * @return the matching t e m p_ phieu thong tin ve nguoi co tien su
     * @throws qldc.pm.tiensu.NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException if a matching t e m p_ phieu thong tin ve nguoi co tien su could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_PhieuThongTinVeNguoiCoTienSu findByTienSuId(long tienSuId)
        throws NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException, SystemException {
        TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu = fetchByTienSuId(tienSuId);

        if (temp_PhieuThongTinVeNguoiCoTienSu == null) {
            StringBundler msg = new StringBundler(4);

            msg.append(_NO_SUCH_ENTITY_WITH_KEY);

            msg.append("tienSuId=");
            msg.append(tienSuId);

            msg.append(StringPool.CLOSE_CURLY_BRACE);

            if (_log.isWarnEnabled()) {
                _log.warn(msg.toString());
            }

            throw new NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException(msg.toString());
        }

        return temp_PhieuThongTinVeNguoiCoTienSu;
    }

    /**
     * Returns the t e m p_ phieu thong tin ve nguoi co tien su where tienSuId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
     *
     * @param tienSuId the tien su ID
     * @return the matching t e m p_ phieu thong tin ve nguoi co tien su, or <code>null</code> if a matching t e m p_ phieu thong tin ve nguoi co tien su could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_PhieuThongTinVeNguoiCoTienSu fetchByTienSuId(long tienSuId)
        throws SystemException {
        return fetchByTienSuId(tienSuId, true);
    }

    /**
     * Returns the t e m p_ phieu thong tin ve nguoi co tien su where tienSuId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
     *
     * @param tienSuId the tien su ID
     * @param retrieveFromCache whether to use the finder cache
     * @return the matching t e m p_ phieu thong tin ve nguoi co tien su, or <code>null</code> if a matching t e m p_ phieu thong tin ve nguoi co tien su could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_PhieuThongTinVeNguoiCoTienSu fetchByTienSuId(long tienSuId,
        boolean retrieveFromCache) throws SystemException {
        Object[] finderArgs = new Object[] { tienSuId };

        Object result = null;

        if (retrieveFromCache) {
            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_TIENSUID,
                    finderArgs, this);
        }

        if (result instanceof TEMP_PhieuThongTinVeNguoiCoTienSu) {
            TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu = (TEMP_PhieuThongTinVeNguoiCoTienSu) result;

            if ((tienSuId != temp_PhieuThongTinVeNguoiCoTienSu.getTienSuId())) {
                result = null;
            }
        }

        if (result == null) {
            StringBundler query = new StringBundler(3);

            query.append(_SQL_SELECT_TEMP_PHIEUTHONGTINVENGUOICOTIENSU_WHERE);

            query.append(_FINDER_COLUMN_TIENSUID_TIENSUID_2);

            String sql = query.toString();

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                QueryPos qPos = QueryPos.getInstance(q);

                qPos.add(tienSuId);

                List<TEMP_PhieuThongTinVeNguoiCoTienSu> list = q.list();

                if (list.isEmpty()) {
                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_TIENSUID,
                        finderArgs, list);
                } else {
                    if ((list.size() > 1) && _log.isWarnEnabled()) {
                        _log.warn(
                            "TEMP_PhieuThongTinVeNguoiCoTienSuPersistenceImpl.fetchByTienSuId(long, boolean) with parameters (" +
                            StringUtil.merge(finderArgs) +
                            ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
                    }

                    TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu =
                        list.get(0);

                    result = temp_PhieuThongTinVeNguoiCoTienSu;

                    cacheResult(temp_PhieuThongTinVeNguoiCoTienSu);

                    if ((temp_PhieuThongTinVeNguoiCoTienSu.getTienSuId() != tienSuId)) {
                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_TIENSUID,
                            finderArgs, temp_PhieuThongTinVeNguoiCoTienSu);
                    }
                }
            } catch (Exception e) {
                FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_TIENSUID,
                    finderArgs);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        if (result instanceof List<?>) {
            return null;
        } else {
            return (TEMP_PhieuThongTinVeNguoiCoTienSu) result;
        }
    }

    /**
     * Removes the t e m p_ phieu thong tin ve nguoi co tien su where tienSuId = &#63; from the database.
     *
     * @param tienSuId the tien su ID
     * @return the t e m p_ phieu thong tin ve nguoi co tien su that was removed
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_PhieuThongTinVeNguoiCoTienSu removeByTienSuId(long tienSuId)
        throws NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException, SystemException {
        TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu = findByTienSuId(tienSuId);

        return remove(temp_PhieuThongTinVeNguoiCoTienSu);
    }

    /**
     * Returns the number of t e m p_ phieu thong tin ve nguoi co tien sus where tienSuId = &#63;.
     *
     * @param tienSuId the tien su ID
     * @return the number of matching t e m p_ phieu thong tin ve nguoi co tien sus
     * @throws SystemException if a system exception occurred
     */
    @Override
    public int countByTienSuId(long tienSuId) throws SystemException {
        FinderPath finderPath = FINDER_PATH_COUNT_BY_TIENSUID;

        Object[] finderArgs = new Object[] { tienSuId };

        Long count = (Long) FinderCacheUtil.getResult(finderPath, finderArgs,
                this);

        if (count == null) {
            StringBundler query = new StringBundler(2);

            query.append(_SQL_COUNT_TEMP_PHIEUTHONGTINVENGUOICOTIENSU_WHERE);

            query.append(_FINDER_COLUMN_TIENSUID_TIENSUID_2);

            String sql = query.toString();

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                QueryPos qPos = QueryPos.getInstance(q);

                qPos.add(tienSuId);

                count = (Long) q.uniqueResult();

                FinderCacheUtil.putResult(finderPath, finderArgs, count);
            } catch (Exception e) {
                FinderCacheUtil.removeResult(finderPath, finderArgs);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return count.intValue();
    }

    /**
     * Returns all the t e m p_ phieu thong tin ve nguoi co tien sus where noiThuongTruDiaChi = &#63;.
     *
     * @param noiThuongTruDiaChi the noi thuong tru dia chi
     * @return the matching t e m p_ phieu thong tin ve nguoi co tien sus
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<TEMP_PhieuThongTinVeNguoiCoTienSu> findByNoiThuongTruDiaChi(
        String noiThuongTruDiaChi) throws SystemException {
        return findByNoiThuongTruDiaChi(noiThuongTruDiaChi, QueryUtil.ALL_POS,
            QueryUtil.ALL_POS, null);
    }

    /**
     * Returns a range of all the t e m p_ phieu thong tin ve nguoi co tien sus where noiThuongTruDiaChi = &#63;.
     *
     * <p>
     * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link qldc.pm.tiensu.model.impl.TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
     * </p>
     *
     * @param noiThuongTruDiaChi the noi thuong tru dia chi
     * @param start the lower bound of the range of t e m p_ phieu thong tin ve nguoi co tien sus
     * @param end the upper bound of the range of t e m p_ phieu thong tin ve nguoi co tien sus (not inclusive)
     * @return the range of matching t e m p_ phieu thong tin ve nguoi co tien sus
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<TEMP_PhieuThongTinVeNguoiCoTienSu> findByNoiThuongTruDiaChi(
        String noiThuongTruDiaChi, int start, int end)
        throws SystemException {
        return findByNoiThuongTruDiaChi(noiThuongTruDiaChi, start, end, null);
    }

    /**
     * Returns an ordered range of all the t e m p_ phieu thong tin ve nguoi co tien sus where noiThuongTruDiaChi = &#63;.
     *
     * <p>
     * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link qldc.pm.tiensu.model.impl.TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
     * </p>
     *
     * @param noiThuongTruDiaChi the noi thuong tru dia chi
     * @param start the lower bound of the range of t e m p_ phieu thong tin ve nguoi co tien sus
     * @param end the upper bound of the range of t e m p_ phieu thong tin ve nguoi co tien sus (not inclusive)
     * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
     * @return the ordered range of matching t e m p_ phieu thong tin ve nguoi co tien sus
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<TEMP_PhieuThongTinVeNguoiCoTienSu> findByNoiThuongTruDiaChi(
        String noiThuongTruDiaChi, int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
        boolean pagination = true;
        FinderPath finderPath = null;
        Object[] finderArgs = null;

        if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
                (orderByComparator == null)) {
            pagination = false;
            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NOITHUONGTRUDIACHI;
            finderArgs = new Object[] { noiThuongTruDiaChi };
        } else {
            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NOITHUONGTRUDIACHI;
            finderArgs = new Object[] {
                    noiThuongTruDiaChi,
                    
                    start, end, orderByComparator
                };
        }

        List<TEMP_PhieuThongTinVeNguoiCoTienSu> list = (List<TEMP_PhieuThongTinVeNguoiCoTienSu>) FinderCacheUtil.getResult(finderPath,
                finderArgs, this);

        if ((list != null) && !list.isEmpty()) {
            for (TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu : list) {
                if (!Validator.equals(noiThuongTruDiaChi,
                            temp_PhieuThongTinVeNguoiCoTienSu.getNoiThuongTruDiaChi())) {
                    list = null;

                    break;
                }
            }
        }

        if (list == null) {
            StringBundler query = null;

            if (orderByComparator != null) {
                query = new StringBundler(3 +
                        (orderByComparator.getOrderByFields().length * 3));
            } else {
                query = new StringBundler(3);
            }

            query.append(_SQL_SELECT_TEMP_PHIEUTHONGTINVENGUOICOTIENSU_WHERE);

            boolean bindNoiThuongTruDiaChi = false;

            if (noiThuongTruDiaChi == null) {
                query.append(_FINDER_COLUMN_NOITHUONGTRUDIACHI_NOITHUONGTRUDIACHI_1);
            } else if (noiThuongTruDiaChi.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_NOITHUONGTRUDIACHI_NOITHUONGTRUDIACHI_3);
            } else {
                bindNoiThuongTruDiaChi = true;

                query.append(_FINDER_COLUMN_NOITHUONGTRUDIACHI_NOITHUONGTRUDIACHI_2);
            }

            if (orderByComparator != null) {
                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
                    orderByComparator);
            } else
             if (pagination) {
                query.append(TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.ORDER_BY_JPQL);
            }

            String sql = query.toString();

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                QueryPos qPos = QueryPos.getInstance(q);

                if (bindNoiThuongTruDiaChi) {
                    qPos.add(noiThuongTruDiaChi);
                }

                if (!pagination) {
                    list = (List<TEMP_PhieuThongTinVeNguoiCoTienSu>) QueryUtil.list(q,
                            getDialect(), start, end, false);

                    Collections.sort(list);

                    list = new UnmodifiableList<TEMP_PhieuThongTinVeNguoiCoTienSu>(list);
                } else {
                    list = (List<TEMP_PhieuThongTinVeNguoiCoTienSu>) QueryUtil.list(q,
                            getDialect(), start, end);
                }

                cacheResult(list);

                FinderCacheUtil.putResult(finderPath, finderArgs, list);
            } catch (Exception e) {
                FinderCacheUtil.removeResult(finderPath, finderArgs);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return list;
    }

    /**
     * Returns the first t e m p_ phieu thong tin ve nguoi co tien su in the ordered set where noiThuongTruDiaChi = &#63;.
     *
     * @param noiThuongTruDiaChi the noi thuong tru dia chi
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the first matching t e m p_ phieu thong tin ve nguoi co tien su
     * @throws qldc.pm.tiensu.NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException if a matching t e m p_ phieu thong tin ve nguoi co tien su could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_PhieuThongTinVeNguoiCoTienSu findByNoiThuongTruDiaChi_First(
        String noiThuongTruDiaChi, OrderByComparator orderByComparator)
        throws NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException, SystemException {
        TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu = fetchByNoiThuongTruDiaChi_First(noiThuongTruDiaChi,
                orderByComparator);

        if (temp_PhieuThongTinVeNguoiCoTienSu != null) {
            return temp_PhieuThongTinVeNguoiCoTienSu;
        }

        StringBundler msg = new StringBundler(4);

        msg.append(_NO_SUCH_ENTITY_WITH_KEY);

        msg.append("noiThuongTruDiaChi=");
        msg.append(noiThuongTruDiaChi);

        msg.append(StringPool.CLOSE_CURLY_BRACE);

        throw new NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException(msg.toString());
    }

    /**
     * Returns the first t e m p_ phieu thong tin ve nguoi co tien su in the ordered set where noiThuongTruDiaChi = &#63;.
     *
     * @param noiThuongTruDiaChi the noi thuong tru dia chi
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the first matching t e m p_ phieu thong tin ve nguoi co tien su, or <code>null</code> if a matching t e m p_ phieu thong tin ve nguoi co tien su could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_PhieuThongTinVeNguoiCoTienSu fetchByNoiThuongTruDiaChi_First(
        String noiThuongTruDiaChi, OrderByComparator orderByComparator)
        throws SystemException {
        List<TEMP_PhieuThongTinVeNguoiCoTienSu> list = findByNoiThuongTruDiaChi(noiThuongTruDiaChi,
                0, 1, orderByComparator);

        if (!list.isEmpty()) {
            return list.get(0);
        }

        return null;
    }

    /**
     * Returns the last t e m p_ phieu thong tin ve nguoi co tien su in the ordered set where noiThuongTruDiaChi = &#63;.
     *
     * @param noiThuongTruDiaChi the noi thuong tru dia chi
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the last matching t e m p_ phieu thong tin ve nguoi co tien su
     * @throws qldc.pm.tiensu.NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException if a matching t e m p_ phieu thong tin ve nguoi co tien su could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_PhieuThongTinVeNguoiCoTienSu findByNoiThuongTruDiaChi_Last(
        String noiThuongTruDiaChi, OrderByComparator orderByComparator)
        throws NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException, SystemException {
        TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu = fetchByNoiThuongTruDiaChi_Last(noiThuongTruDiaChi,
                orderByComparator);

        if (temp_PhieuThongTinVeNguoiCoTienSu != null) {
            return temp_PhieuThongTinVeNguoiCoTienSu;
        }

        StringBundler msg = new StringBundler(4);

        msg.append(_NO_SUCH_ENTITY_WITH_KEY);

        msg.append("noiThuongTruDiaChi=");
        msg.append(noiThuongTruDiaChi);

        msg.append(StringPool.CLOSE_CURLY_BRACE);

        throw new NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException(msg.toString());
    }

    /**
     * Returns the last t e m p_ phieu thong tin ve nguoi co tien su in the ordered set where noiThuongTruDiaChi = &#63;.
     *
     * @param noiThuongTruDiaChi the noi thuong tru dia chi
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the last matching t e m p_ phieu thong tin ve nguoi co tien su, or <code>null</code> if a matching t e m p_ phieu thong tin ve nguoi co tien su could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_PhieuThongTinVeNguoiCoTienSu fetchByNoiThuongTruDiaChi_Last(
        String noiThuongTruDiaChi, OrderByComparator orderByComparator)
        throws SystemException {
        int count = countByNoiThuongTruDiaChi(noiThuongTruDiaChi);

        if (count == 0) {
            return null;
        }

        List<TEMP_PhieuThongTinVeNguoiCoTienSu> list = findByNoiThuongTruDiaChi(noiThuongTruDiaChi,
                count - 1, count, orderByComparator);

        if (!list.isEmpty()) {
            return list.get(0);
        }

        return null;
    }

    /**
     * Returns the t e m p_ phieu thong tin ve nguoi co tien sus before and after the current t e m p_ phieu thong tin ve nguoi co tien su in the ordered set where noiThuongTruDiaChi = &#63;.
     *
     * @param phieuThongTinVeNguoiCoTienSuId the primary key of the current t e m p_ phieu thong tin ve nguoi co tien su
     * @param noiThuongTruDiaChi the noi thuong tru dia chi
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the previous, current, and next t e m p_ phieu thong tin ve nguoi co tien su
     * @throws qldc.pm.tiensu.NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException if a t e m p_ phieu thong tin ve nguoi co tien su with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_PhieuThongTinVeNguoiCoTienSu[] findByNoiThuongTruDiaChi_PrevAndNext(
        long phieuThongTinVeNguoiCoTienSuId, String noiThuongTruDiaChi,
        OrderByComparator orderByComparator)
        throws NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException, SystemException {
        TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu = findByPrimaryKey(phieuThongTinVeNguoiCoTienSuId);

        Session session = null;

        try {
            session = openSession();

            TEMP_PhieuThongTinVeNguoiCoTienSu[] array = new TEMP_PhieuThongTinVeNguoiCoTienSuImpl[3];

            array[0] = getByNoiThuongTruDiaChi_PrevAndNext(session,
                    temp_PhieuThongTinVeNguoiCoTienSu, noiThuongTruDiaChi,
                    orderByComparator, true);

            array[1] = temp_PhieuThongTinVeNguoiCoTienSu;

            array[2] = getByNoiThuongTruDiaChi_PrevAndNext(session,
                    temp_PhieuThongTinVeNguoiCoTienSu, noiThuongTruDiaChi,
                    orderByComparator, false);

            return array;
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    protected TEMP_PhieuThongTinVeNguoiCoTienSu getByNoiThuongTruDiaChi_PrevAndNext(
        Session session,
        TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu,
        String noiThuongTruDiaChi, OrderByComparator orderByComparator,
        boolean previous) {
        StringBundler query = null;

        if (orderByComparator != null) {
            query = new StringBundler(6 +
                    (orderByComparator.getOrderByFields().length * 6));
        } else {
            query = new StringBundler(3);
        }

        query.append(_SQL_SELECT_TEMP_PHIEUTHONGTINVENGUOICOTIENSU_WHERE);

        boolean bindNoiThuongTruDiaChi = false;

        if (noiThuongTruDiaChi == null) {
            query.append(_FINDER_COLUMN_NOITHUONGTRUDIACHI_NOITHUONGTRUDIACHI_1);
        } else if (noiThuongTruDiaChi.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_NOITHUONGTRUDIACHI_NOITHUONGTRUDIACHI_3);
        } else {
            bindNoiThuongTruDiaChi = true;

            query.append(_FINDER_COLUMN_NOITHUONGTRUDIACHI_NOITHUONGTRUDIACHI_2);
        }

        if (orderByComparator != null) {
            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

            if (orderByConditionFields.length > 0) {
                query.append(WHERE_AND);
            }

            for (int i = 0; i < orderByConditionFields.length; i++) {
                query.append(_ORDER_BY_ENTITY_ALIAS);
                query.append(orderByConditionFields[i]);

                if ((i + 1) < orderByConditionFields.length) {
                    if (orderByComparator.isAscending() ^ previous) {
                        query.append(WHERE_GREATER_THAN_HAS_NEXT);
                    } else {
                        query.append(WHERE_LESSER_THAN_HAS_NEXT);
                    }
                } else {
                    if (orderByComparator.isAscending() ^ previous) {
                        query.append(WHERE_GREATER_THAN);
                    } else {
                        query.append(WHERE_LESSER_THAN);
                    }
                }
            }

            query.append(ORDER_BY_CLAUSE);

            String[] orderByFields = orderByComparator.getOrderByFields();

            for (int i = 0; i < orderByFields.length; i++) {
                query.append(_ORDER_BY_ENTITY_ALIAS);
                query.append(orderByFields[i]);

                if ((i + 1) < orderByFields.length) {
                    if (orderByComparator.isAscending() ^ previous) {
                        query.append(ORDER_BY_ASC_HAS_NEXT);
                    } else {
                        query.append(ORDER_BY_DESC_HAS_NEXT);
                    }
                } else {
                    if (orderByComparator.isAscending() ^ previous) {
                        query.append(ORDER_BY_ASC);
                    } else {
                        query.append(ORDER_BY_DESC);
                    }
                }
            }
        } else {
            query.append(TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Query q = session.createQuery(sql);

        q.setFirstResult(0);
        q.setMaxResults(2);

        QueryPos qPos = QueryPos.getInstance(q);

        if (bindNoiThuongTruDiaChi) {
            qPos.add(noiThuongTruDiaChi);
        }

        if (orderByComparator != null) {
            Object[] values = orderByComparator.getOrderByConditionValues(temp_PhieuThongTinVeNguoiCoTienSu);

            for (Object value : values) {
                qPos.add(value);
            }
        }

        List<TEMP_PhieuThongTinVeNguoiCoTienSu> list = q.list();

        if (list.size() == 2) {
            return list.get(1);
        } else {
            return null;
        }
    }

    /**
     * Removes all the t e m p_ phieu thong tin ve nguoi co tien sus where noiThuongTruDiaChi = &#63; from the database.
     *
     * @param noiThuongTruDiaChi the noi thuong tru dia chi
     * @throws SystemException if a system exception occurred
     */
    @Override
    public void removeByNoiThuongTruDiaChi(String noiThuongTruDiaChi)
        throws SystemException {
        for (TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu : findByNoiThuongTruDiaChi(
                noiThuongTruDiaChi, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
            remove(temp_PhieuThongTinVeNguoiCoTienSu);
        }
    }

    /**
     * Returns the number of t e m p_ phieu thong tin ve nguoi co tien sus where noiThuongTruDiaChi = &#63;.
     *
     * @param noiThuongTruDiaChi the noi thuong tru dia chi
     * @return the number of matching t e m p_ phieu thong tin ve nguoi co tien sus
     * @throws SystemException if a system exception occurred
     */
    @Override
    public int countByNoiThuongTruDiaChi(String noiThuongTruDiaChi)
        throws SystemException {
        FinderPath finderPath = FINDER_PATH_COUNT_BY_NOITHUONGTRUDIACHI;

        Object[] finderArgs = new Object[] { noiThuongTruDiaChi };

        Long count = (Long) FinderCacheUtil.getResult(finderPath, finderArgs,
                this);

        if (count == null) {
            StringBundler query = new StringBundler(2);

            query.append(_SQL_COUNT_TEMP_PHIEUTHONGTINVENGUOICOTIENSU_WHERE);

            boolean bindNoiThuongTruDiaChi = false;

            if (noiThuongTruDiaChi == null) {
                query.append(_FINDER_COLUMN_NOITHUONGTRUDIACHI_NOITHUONGTRUDIACHI_1);
            } else if (noiThuongTruDiaChi.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_NOITHUONGTRUDIACHI_NOITHUONGTRUDIACHI_3);
            } else {
                bindNoiThuongTruDiaChi = true;

                query.append(_FINDER_COLUMN_NOITHUONGTRUDIACHI_NOITHUONGTRUDIACHI_2);
            }

            String sql = query.toString();

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                QueryPos qPos = QueryPos.getInstance(q);

                if (bindNoiThuongTruDiaChi) {
                    qPos.add(noiThuongTruDiaChi);
                }

                count = (Long) q.uniqueResult();

                FinderCacheUtil.putResult(finderPath, finderArgs, count);
            } catch (Exception e) {
                FinderCacheUtil.removeResult(finderPath, finderArgs);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return count.intValue();
    }

    /**
     * Caches the t e m p_ phieu thong tin ve nguoi co tien su in the entity cache if it is enabled.
     *
     * @param temp_PhieuThongTinVeNguoiCoTienSu the t e m p_ phieu thong tin ve nguoi co tien su
     */
    @Override
    public void cacheResult(
        TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu) {
        EntityCacheUtil.putResult(TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.ENTITY_CACHE_ENABLED,
            TEMP_PhieuThongTinVeNguoiCoTienSuImpl.class,
            temp_PhieuThongTinVeNguoiCoTienSu.getPrimaryKey(),
            temp_PhieuThongTinVeNguoiCoTienSu);

        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MASOHOSOTIENSUTUTOAAN,
            new Object[] {
                temp_PhieuThongTinVeNguoiCoTienSu.getMaSoHoSoTienSuTuToaAn()
            }, temp_PhieuThongTinVeNguoiCoTienSu);

        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_TIENSUID,
            new Object[] { temp_PhieuThongTinVeNguoiCoTienSu.getTienSuId() },
            temp_PhieuThongTinVeNguoiCoTienSu);

        temp_PhieuThongTinVeNguoiCoTienSu.resetOriginalValues();
    }

    /**
     * Caches the t e m p_ phieu thong tin ve nguoi co tien sus in the entity cache if it is enabled.
     *
     * @param temp_PhieuThongTinVeNguoiCoTienSus the t e m p_ phieu thong tin ve nguoi co tien sus
     */
    @Override
    public void cacheResult(
        List<TEMP_PhieuThongTinVeNguoiCoTienSu> temp_PhieuThongTinVeNguoiCoTienSus) {
        for (TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu : temp_PhieuThongTinVeNguoiCoTienSus) {
            if (EntityCacheUtil.getResult(
                        TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.ENTITY_CACHE_ENABLED,
                        TEMP_PhieuThongTinVeNguoiCoTienSuImpl.class,
                        temp_PhieuThongTinVeNguoiCoTienSu.getPrimaryKey()) == null) {
                cacheResult(temp_PhieuThongTinVeNguoiCoTienSu);
            } else {
                temp_PhieuThongTinVeNguoiCoTienSu.resetOriginalValues();
            }
        }
    }

    /**
     * Clears the cache for all t e m p_ phieu thong tin ve nguoi co tien sus.
     *
     * <p>
     * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
     * </p>
     */
    @Override
    public void clearCache() {
        if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
            CacheRegistryUtil.clear(TEMP_PhieuThongTinVeNguoiCoTienSuImpl.class.getName());
        }

        EntityCacheUtil.clearCache(TEMP_PhieuThongTinVeNguoiCoTienSuImpl.class.getName());

        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    }

    /**
     * Clears the cache for the t e m p_ phieu thong tin ve nguoi co tien su.
     *
     * <p>
     * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
     * </p>
     */
    @Override
    public void clearCache(
        TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu) {
        EntityCacheUtil.removeResult(TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.ENTITY_CACHE_ENABLED,
            TEMP_PhieuThongTinVeNguoiCoTienSuImpl.class,
            temp_PhieuThongTinVeNguoiCoTienSu.getPrimaryKey());

        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

        clearUniqueFindersCache(temp_PhieuThongTinVeNguoiCoTienSu);
    }

    @Override
    public void clearCache(
        List<TEMP_PhieuThongTinVeNguoiCoTienSu> temp_PhieuThongTinVeNguoiCoTienSus) {
        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

        for (TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu : temp_PhieuThongTinVeNguoiCoTienSus) {
            EntityCacheUtil.removeResult(TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.ENTITY_CACHE_ENABLED,
                TEMP_PhieuThongTinVeNguoiCoTienSuImpl.class,
                temp_PhieuThongTinVeNguoiCoTienSu.getPrimaryKey());

            clearUniqueFindersCache(temp_PhieuThongTinVeNguoiCoTienSu);
        }
    }

    protected void cacheUniqueFindersCache(
        TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu) {
        if (temp_PhieuThongTinVeNguoiCoTienSu.isNew()) {
            Object[] args = new Object[] {
                    temp_PhieuThongTinVeNguoiCoTienSu.getMaSoHoSoTienSuTuToaAn()
                };

            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_MASOHOSOTIENSUTUTOAAN,
                args, Long.valueOf(1));
            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MASOHOSOTIENSUTUTOAAN,
                args, temp_PhieuThongTinVeNguoiCoTienSu);

            args = new Object[] { temp_PhieuThongTinVeNguoiCoTienSu.getTienSuId() };

            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TIENSUID, args,
                Long.valueOf(1));
            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_TIENSUID, args,
                temp_PhieuThongTinVeNguoiCoTienSu);
        } else {
            TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl temp_PhieuThongTinVeNguoiCoTienSuModelImpl =
                (TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl) temp_PhieuThongTinVeNguoiCoTienSu;

            if ((temp_PhieuThongTinVeNguoiCoTienSuModelImpl.getColumnBitmask() &
                    FINDER_PATH_FETCH_BY_MASOHOSOTIENSUTUTOAAN.getColumnBitmask()) != 0) {
                Object[] args = new Object[] {
                        temp_PhieuThongTinVeNguoiCoTienSu.getMaSoHoSoTienSuTuToaAn()
                    };

                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_MASOHOSOTIENSUTUTOAAN,
                    args, Long.valueOf(1));
                FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MASOHOSOTIENSUTUTOAAN,
                    args, temp_PhieuThongTinVeNguoiCoTienSu);
            }

            if ((temp_PhieuThongTinVeNguoiCoTienSuModelImpl.getColumnBitmask() &
                    FINDER_PATH_FETCH_BY_TIENSUID.getColumnBitmask()) != 0) {
                Object[] args = new Object[] {
                        temp_PhieuThongTinVeNguoiCoTienSu.getTienSuId()
                    };

                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TIENSUID, args,
                    Long.valueOf(1));
                FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_TIENSUID, args,
                    temp_PhieuThongTinVeNguoiCoTienSu);
            }
        }
    }

    protected void clearUniqueFindersCache(
        TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu) {
        TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl temp_PhieuThongTinVeNguoiCoTienSuModelImpl =
            (TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl) temp_PhieuThongTinVeNguoiCoTienSu;

        Object[] args = new Object[] {
                temp_PhieuThongTinVeNguoiCoTienSu.getMaSoHoSoTienSuTuToaAn()
            };

        FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_MASOHOSOTIENSUTUTOAAN,
            args);
        FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MASOHOSOTIENSUTUTOAAN,
            args);

        if ((temp_PhieuThongTinVeNguoiCoTienSuModelImpl.getColumnBitmask() &
                FINDER_PATH_FETCH_BY_MASOHOSOTIENSUTUTOAAN.getColumnBitmask()) != 0) {
            args = new Object[] {
                    temp_PhieuThongTinVeNguoiCoTienSuModelImpl.getOriginalMaSoHoSoTienSuTuToaAn()
                };

            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_MASOHOSOTIENSUTUTOAAN,
                args);
            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MASOHOSOTIENSUTUTOAAN,
                args);
        }

        args = new Object[] { temp_PhieuThongTinVeNguoiCoTienSu.getTienSuId() };

        FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TIENSUID, args);
        FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_TIENSUID, args);

        if ((temp_PhieuThongTinVeNguoiCoTienSuModelImpl.getColumnBitmask() &
                FINDER_PATH_FETCH_BY_TIENSUID.getColumnBitmask()) != 0) {
            args = new Object[] {
                    temp_PhieuThongTinVeNguoiCoTienSuModelImpl.getOriginalTienSuId()
                };

            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TIENSUID, args);
            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_TIENSUID, args);
        }
    }

    /**
     * Creates a new t e m p_ phieu thong tin ve nguoi co tien su with the primary key. Does not add the t e m p_ phieu thong tin ve nguoi co tien su to the database.
     *
     * @param phieuThongTinVeNguoiCoTienSuId the primary key for the new t e m p_ phieu thong tin ve nguoi co tien su
     * @return the new t e m p_ phieu thong tin ve nguoi co tien su
     */
    @Override
    public TEMP_PhieuThongTinVeNguoiCoTienSu create(
        long phieuThongTinVeNguoiCoTienSuId) {
        TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu = new TEMP_PhieuThongTinVeNguoiCoTienSuImpl();

        temp_PhieuThongTinVeNguoiCoTienSu.setNew(true);
        temp_PhieuThongTinVeNguoiCoTienSu.setPrimaryKey(phieuThongTinVeNguoiCoTienSuId);

        return temp_PhieuThongTinVeNguoiCoTienSu;
    }

    /**
     * Removes the t e m p_ phieu thong tin ve nguoi co tien su with the primary key from the database. Also notifies the appropriate model listeners.
     *
     * @param phieuThongTinVeNguoiCoTienSuId the primary key of the t e m p_ phieu thong tin ve nguoi co tien su
     * @return the t e m p_ phieu thong tin ve nguoi co tien su that was removed
     * @throws qldc.pm.tiensu.NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException if a t e m p_ phieu thong tin ve nguoi co tien su with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_PhieuThongTinVeNguoiCoTienSu remove(
        long phieuThongTinVeNguoiCoTienSuId)
        throws NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException, SystemException {
        return remove((Serializable) phieuThongTinVeNguoiCoTienSuId);
    }

    /**
     * Removes the t e m p_ phieu thong tin ve nguoi co tien su with the primary key from the database. Also notifies the appropriate model listeners.
     *
     * @param primaryKey the primary key of the t e m p_ phieu thong tin ve nguoi co tien su
     * @return the t e m p_ phieu thong tin ve nguoi co tien su that was removed
     * @throws qldc.pm.tiensu.NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException if a t e m p_ phieu thong tin ve nguoi co tien su with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_PhieuThongTinVeNguoiCoTienSu remove(Serializable primaryKey)
        throws NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException, SystemException {
        Session session = null;

        try {
            session = openSession();

            TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu = (TEMP_PhieuThongTinVeNguoiCoTienSu) session.get(TEMP_PhieuThongTinVeNguoiCoTienSuImpl.class,
                    primaryKey);

            if (temp_PhieuThongTinVeNguoiCoTienSu == null) {
                if (_log.isWarnEnabled()) {
                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
                }

                throw new NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
                    primaryKey);
            }

            return remove(temp_PhieuThongTinVeNguoiCoTienSu);
        } catch (NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException nsee) {
            throw nsee;
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    @Override
    protected TEMP_PhieuThongTinVeNguoiCoTienSu removeImpl(
        TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu)
        throws SystemException {
        temp_PhieuThongTinVeNguoiCoTienSu = toUnwrappedModel(temp_PhieuThongTinVeNguoiCoTienSu);

        Session session = null;

        try {
            session = openSession();

            if (!session.contains(temp_PhieuThongTinVeNguoiCoTienSu)) {
                temp_PhieuThongTinVeNguoiCoTienSu = (TEMP_PhieuThongTinVeNguoiCoTienSu) session.get(TEMP_PhieuThongTinVeNguoiCoTienSuImpl.class,
                        temp_PhieuThongTinVeNguoiCoTienSu.getPrimaryKeyObj());
            }

            if (temp_PhieuThongTinVeNguoiCoTienSu != null) {
                session.delete(temp_PhieuThongTinVeNguoiCoTienSu);
            }
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }

        if (temp_PhieuThongTinVeNguoiCoTienSu != null) {
            clearCache(temp_PhieuThongTinVeNguoiCoTienSu);
        }

        return temp_PhieuThongTinVeNguoiCoTienSu;
    }

    @Override
    public TEMP_PhieuThongTinVeNguoiCoTienSu updateImpl(
        qldc.pm.tiensu.model.TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu)
        throws SystemException {
        temp_PhieuThongTinVeNguoiCoTienSu = toUnwrappedModel(temp_PhieuThongTinVeNguoiCoTienSu);

        boolean isNew = temp_PhieuThongTinVeNguoiCoTienSu.isNew();

        TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl temp_PhieuThongTinVeNguoiCoTienSuModelImpl =
            (TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl) temp_PhieuThongTinVeNguoiCoTienSu;

        Session session = null;

        try {
            session = openSession();

            if (temp_PhieuThongTinVeNguoiCoTienSu.isNew()) {
                session.save(temp_PhieuThongTinVeNguoiCoTienSu);

                temp_PhieuThongTinVeNguoiCoTienSu.setNew(false);
            } else {
                session.merge(temp_PhieuThongTinVeNguoiCoTienSu);
            }
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }

        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

        if (isNew ||
                !TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.COLUMN_BITMASK_ENABLED) {
            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
        }
        else {
            if ((temp_PhieuThongTinVeNguoiCoTienSuModelImpl.getColumnBitmask() &
                    FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SODINHDANHCANHAN.getColumnBitmask()) != 0) {
                Object[] args = new Object[] {
                        temp_PhieuThongTinVeNguoiCoTienSuModelImpl.getOriginalSoDinhDanhCaNhan()
                    };

                FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SODINHDANHCANHAN,
                    args);
                FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SODINHDANHCANHAN,
                    args);

                args = new Object[] {
                        temp_PhieuThongTinVeNguoiCoTienSuModelImpl.getSoDinhDanhCaNhan()
                    };

                FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SODINHDANHCANHAN,
                    args);
                FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SODINHDANHCANHAN,
                    args);
            }

            if ((temp_PhieuThongTinVeNguoiCoTienSuModelImpl.getColumnBitmask() &
                    FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NOITHUONGTRUDIACHI.getColumnBitmask()) != 0) {
                Object[] args = new Object[] {
                        temp_PhieuThongTinVeNguoiCoTienSuModelImpl.getOriginalNoiThuongTruDiaChi()
                    };

                FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NOITHUONGTRUDIACHI,
                    args);
                FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NOITHUONGTRUDIACHI,
                    args);

                args = new Object[] {
                        temp_PhieuThongTinVeNguoiCoTienSuModelImpl.getNoiThuongTruDiaChi()
                    };

                FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NOITHUONGTRUDIACHI,
                    args);
                FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NOITHUONGTRUDIACHI,
                    args);
            }
        }

        EntityCacheUtil.putResult(TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.ENTITY_CACHE_ENABLED,
            TEMP_PhieuThongTinVeNguoiCoTienSuImpl.class,
            temp_PhieuThongTinVeNguoiCoTienSu.getPrimaryKey(),
            temp_PhieuThongTinVeNguoiCoTienSu);

        clearUniqueFindersCache(temp_PhieuThongTinVeNguoiCoTienSu);
        cacheUniqueFindersCache(temp_PhieuThongTinVeNguoiCoTienSu);

        return temp_PhieuThongTinVeNguoiCoTienSu;
    }

    protected TEMP_PhieuThongTinVeNguoiCoTienSu toUnwrappedModel(
        TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu) {
        if (temp_PhieuThongTinVeNguoiCoTienSu instanceof TEMP_PhieuThongTinVeNguoiCoTienSuImpl) {
            return temp_PhieuThongTinVeNguoiCoTienSu;
        }

        TEMP_PhieuThongTinVeNguoiCoTienSuImpl temp_PhieuThongTinVeNguoiCoTienSuImpl =
            new TEMP_PhieuThongTinVeNguoiCoTienSuImpl();

        temp_PhieuThongTinVeNguoiCoTienSuImpl.setNew(temp_PhieuThongTinVeNguoiCoTienSu.isNew());
        temp_PhieuThongTinVeNguoiCoTienSuImpl.setPrimaryKey(temp_PhieuThongTinVeNguoiCoTienSu.getPrimaryKey());

        temp_PhieuThongTinVeNguoiCoTienSuImpl.setPhieuThongTinVeNguoiCoTienSuId(temp_PhieuThongTinVeNguoiCoTienSu.getPhieuThongTinVeNguoiCoTienSuId());
        temp_PhieuThongTinVeNguoiCoTienSuImpl.setUserId(temp_PhieuThongTinVeNguoiCoTienSu.getUserId());
        temp_PhieuThongTinVeNguoiCoTienSuImpl.setUserName(temp_PhieuThongTinVeNguoiCoTienSu.getUserName());
        temp_PhieuThongTinVeNguoiCoTienSuImpl.setCreateDate(temp_PhieuThongTinVeNguoiCoTienSu.getCreateDate());
        temp_PhieuThongTinVeNguoiCoTienSuImpl.setModifiedDate(temp_PhieuThongTinVeNguoiCoTienSu.getModifiedDate());
        temp_PhieuThongTinVeNguoiCoTienSuImpl.setTienSuId(temp_PhieuThongTinVeNguoiCoTienSu.getTienSuId());
        temp_PhieuThongTinVeNguoiCoTienSuImpl.setMaSoHoSoTienSuTuToaAn(temp_PhieuThongTinVeNguoiCoTienSu.getMaSoHoSoTienSuTuToaAn());
        temp_PhieuThongTinVeNguoiCoTienSuImpl.setNguoiTrichLuc(temp_PhieuThongTinVeNguoiCoTienSu.getNguoiTrichLuc());
        temp_PhieuThongTinVeNguoiCoTienSuImpl.setThamPhan(temp_PhieuThongTinVeNguoiCoTienSu.getThamPhan());
        temp_PhieuThongTinVeNguoiCoTienSuImpl.setSoDinhDanhCaNhan(temp_PhieuThongTinVeNguoiCoTienSu.getSoDinhDanhCaNhan());
        temp_PhieuThongTinVeNguoiCoTienSuImpl.setChuThich(temp_PhieuThongTinVeNguoiCoTienSu.getChuThich());
        temp_PhieuThongTinVeNguoiCoTienSuImpl.setNoiTamTruDiaChi(temp_PhieuThongTinVeNguoiCoTienSu.getNoiTamTruDiaChi());
        temp_PhieuThongTinVeNguoiCoTienSuImpl.setNoiThuongTruDiaChi(temp_PhieuThongTinVeNguoiCoTienSu.getNoiThuongTruDiaChi());
        temp_PhieuThongTinVeNguoiCoTienSuImpl.setHoTenVoHoacChong(temp_PhieuThongTinVeNguoiCoTienSu.getHoTenVoHoacChong());
        temp_PhieuThongTinVeNguoiCoTienSuImpl.setHoTenCha(temp_PhieuThongTinVeNguoiCoTienSu.getHoTenCha());
        temp_PhieuThongTinVeNguoiCoTienSuImpl.setHoTenMe(temp_PhieuThongTinVeNguoiCoTienSu.getHoTenMe());

        return temp_PhieuThongTinVeNguoiCoTienSuImpl;
    }

    /**
     * Returns the t e m p_ phieu thong tin ve nguoi co tien su with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
     *
     * @param primaryKey the primary key of the t e m p_ phieu thong tin ve nguoi co tien su
     * @return the t e m p_ phieu thong tin ve nguoi co tien su
     * @throws qldc.pm.tiensu.NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException if a t e m p_ phieu thong tin ve nguoi co tien su with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_PhieuThongTinVeNguoiCoTienSu findByPrimaryKey(
        Serializable primaryKey)
        throws NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException, SystemException {
        TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu = fetchByPrimaryKey(primaryKey);

        if (temp_PhieuThongTinVeNguoiCoTienSu == null) {
            if (_log.isWarnEnabled()) {
                _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
            }

            throw new NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
                primaryKey);
        }

        return temp_PhieuThongTinVeNguoiCoTienSu;
    }

    /**
     * Returns the t e m p_ phieu thong tin ve nguoi co tien su with the primary key or throws a {@link qldc.pm.tiensu.NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException} if it could not be found.
     *
     * @param phieuThongTinVeNguoiCoTienSuId the primary key of the t e m p_ phieu thong tin ve nguoi co tien su
     * @return the t e m p_ phieu thong tin ve nguoi co tien su
     * @throws qldc.pm.tiensu.NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException if a t e m p_ phieu thong tin ve nguoi co tien su with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_PhieuThongTinVeNguoiCoTienSu findByPrimaryKey(
        long phieuThongTinVeNguoiCoTienSuId)
        throws NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException, SystemException {
        return findByPrimaryKey((Serializable) phieuThongTinVeNguoiCoTienSuId);
    }

    /**
     * Returns the t e m p_ phieu thong tin ve nguoi co tien su with the primary key or returns <code>null</code> if it could not be found.
     *
     * @param primaryKey the primary key of the t e m p_ phieu thong tin ve nguoi co tien su
     * @return the t e m p_ phieu thong tin ve nguoi co tien su, or <code>null</code> if a t e m p_ phieu thong tin ve nguoi co tien su with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_PhieuThongTinVeNguoiCoTienSu fetchByPrimaryKey(
        Serializable primaryKey) throws SystemException {
        TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu = (TEMP_PhieuThongTinVeNguoiCoTienSu) EntityCacheUtil.getResult(TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.ENTITY_CACHE_ENABLED,
                TEMP_PhieuThongTinVeNguoiCoTienSuImpl.class, primaryKey);

        if (temp_PhieuThongTinVeNguoiCoTienSu == _nullTEMP_PhieuThongTinVeNguoiCoTienSu) {
            return null;
        }

        if (temp_PhieuThongTinVeNguoiCoTienSu == null) {
            Session session = null;

            try {
                session = openSession();

                temp_PhieuThongTinVeNguoiCoTienSu = (TEMP_PhieuThongTinVeNguoiCoTienSu) session.get(TEMP_PhieuThongTinVeNguoiCoTienSuImpl.class,
                        primaryKey);

                if (temp_PhieuThongTinVeNguoiCoTienSu != null) {
                    cacheResult(temp_PhieuThongTinVeNguoiCoTienSu);
                } else {
                    EntityCacheUtil.putResult(TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.ENTITY_CACHE_ENABLED,
                        TEMP_PhieuThongTinVeNguoiCoTienSuImpl.class,
                        primaryKey, _nullTEMP_PhieuThongTinVeNguoiCoTienSu);
                }
            } catch (Exception e) {
                EntityCacheUtil.removeResult(TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.ENTITY_CACHE_ENABLED,
                    TEMP_PhieuThongTinVeNguoiCoTienSuImpl.class, primaryKey);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return temp_PhieuThongTinVeNguoiCoTienSu;
    }

    /**
     * Returns the t e m p_ phieu thong tin ve nguoi co tien su with the primary key or returns <code>null</code> if it could not be found.
     *
     * @param phieuThongTinVeNguoiCoTienSuId the primary key of the t e m p_ phieu thong tin ve nguoi co tien su
     * @return the t e m p_ phieu thong tin ve nguoi co tien su, or <code>null</code> if a t e m p_ phieu thong tin ve nguoi co tien su with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public TEMP_PhieuThongTinVeNguoiCoTienSu fetchByPrimaryKey(
        long phieuThongTinVeNguoiCoTienSuId) throws SystemException {
        return fetchByPrimaryKey((Serializable) phieuThongTinVeNguoiCoTienSuId);
    }

    /**
     * Returns all the t e m p_ phieu thong tin ve nguoi co tien sus.
     *
     * @return the t e m p_ phieu thong tin ve nguoi co tien sus
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<TEMP_PhieuThongTinVeNguoiCoTienSu> findAll()
        throws SystemException {
        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
    }

    /**
     * Returns a range of all the t e m p_ phieu thong tin ve nguoi co tien sus.
     *
     * <p>
     * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link qldc.pm.tiensu.model.impl.TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
     * </p>
     *
     * @param start the lower bound of the range of t e m p_ phieu thong tin ve nguoi co tien sus
     * @param end the upper bound of the range of t e m p_ phieu thong tin ve nguoi co tien sus (not inclusive)
     * @return the range of t e m p_ phieu thong tin ve nguoi co tien sus
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<TEMP_PhieuThongTinVeNguoiCoTienSu> findAll(int start, int end)
        throws SystemException {
        return findAll(start, end, null);
    }

    /**
     * Returns an ordered range of all the t e m p_ phieu thong tin ve nguoi co tien sus.
     *
     * <p>
     * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link qldc.pm.tiensu.model.impl.TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
     * </p>
     *
     * @param start the lower bound of the range of t e m p_ phieu thong tin ve nguoi co tien sus
     * @param end the upper bound of the range of t e m p_ phieu thong tin ve nguoi co tien sus (not inclusive)
     * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
     * @return the ordered range of t e m p_ phieu thong tin ve nguoi co tien sus
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<TEMP_PhieuThongTinVeNguoiCoTienSu> findAll(int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
        boolean pagination = true;
        FinderPath finderPath = null;
        Object[] finderArgs = null;

        if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
                (orderByComparator == null)) {
            pagination = false;
            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
            finderArgs = FINDER_ARGS_EMPTY;
        } else {
            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
            finderArgs = new Object[] { start, end, orderByComparator };
        }

        List<TEMP_PhieuThongTinVeNguoiCoTienSu> list = (List<TEMP_PhieuThongTinVeNguoiCoTienSu>) FinderCacheUtil.getResult(finderPath,
                finderArgs, this);

        if (list == null) {
            StringBundler query = null;
            String sql = null;

            if (orderByComparator != null) {
                query = new StringBundler(2 +
                        (orderByComparator.getOrderByFields().length * 3));

                query.append(_SQL_SELECT_TEMP_PHIEUTHONGTINVENGUOICOTIENSU);

                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
                    orderByComparator);

                sql = query.toString();
            } else {
                sql = _SQL_SELECT_TEMP_PHIEUTHONGTINVENGUOICOTIENSU;

                if (pagination) {
                    sql = sql.concat(TEMP_PhieuThongTinVeNguoiCoTienSuModelImpl.ORDER_BY_JPQL);
                }
            }

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                if (!pagination) {
                    list = (List<TEMP_PhieuThongTinVeNguoiCoTienSu>) QueryUtil.list(q,
                            getDialect(), start, end, false);

                    Collections.sort(list);

                    list = new UnmodifiableList<TEMP_PhieuThongTinVeNguoiCoTienSu>(list);
                } else {
                    list = (List<TEMP_PhieuThongTinVeNguoiCoTienSu>) QueryUtil.list(q,
                            getDialect(), start, end);
                }

                cacheResult(list);

                FinderCacheUtil.putResult(finderPath, finderArgs, list);
            } catch (Exception e) {
                FinderCacheUtil.removeResult(finderPath, finderArgs);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return list;
    }

    /**
     * Removes all the t e m p_ phieu thong tin ve nguoi co tien sus from the database.
     *
     * @throws SystemException if a system exception occurred
     */
    @Override
    public void removeAll() throws SystemException {
        for (TEMP_PhieuThongTinVeNguoiCoTienSu temp_PhieuThongTinVeNguoiCoTienSu : findAll()) {
            remove(temp_PhieuThongTinVeNguoiCoTienSu);
        }
    }

    /**
     * Returns the number of t e m p_ phieu thong tin ve nguoi co tien sus.
     *
     * @return the number of t e m p_ phieu thong tin ve nguoi co tien sus
     * @throws SystemException if a system exception occurred
     */
    @Override
    public int countAll() throws SystemException {
        Long count = (Long) FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
                FINDER_ARGS_EMPTY, this);

        if (count == null) {
            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(_SQL_COUNT_TEMP_PHIEUTHONGTINVENGUOICOTIENSU);

                count = (Long) q.uniqueResult();

                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
                    FINDER_ARGS_EMPTY, count);
            } catch (Exception e) {
                FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
                    FINDER_ARGS_EMPTY);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return count.intValue();
    }

    /**
     * Initializes the t e m p_ phieu thong tin ve nguoi co tien su persistence.
     */
    public void afterPropertiesSet() {
        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
                    com.liferay.util.service.ServiceProps.get(
                        "value.object.listener.qldc.pm.tiensu.model.TEMP_PhieuThongTinVeNguoiCoTienSu")));

        if (listenerClassNames.length > 0) {
            try {
                List<ModelListener<TEMP_PhieuThongTinVeNguoiCoTienSu>> listenersList =
                    new ArrayList<ModelListener<TEMP_PhieuThongTinVeNguoiCoTienSu>>();

                for (String listenerClassName : listenerClassNames) {
                    listenersList.add((ModelListener<TEMP_PhieuThongTinVeNguoiCoTienSu>) InstanceFactory.newInstance(
                            getClassLoader(), listenerClassName));
                }

                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
            } catch (Exception e) {
                _log.error(e);
            }
        }
    }

    public void destroy() {
        EntityCacheUtil.removeCache(TEMP_PhieuThongTinVeNguoiCoTienSuImpl.class.getName());
        FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
        FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
        FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    }
}
